<template>
    <ul>
        <li @mouseover="active = i" @mouseleave="active = null" :class="active === i ? 'active' : ''" v-for="(item, i) in list" v-show="item.state === cur" :key="item.id">
            <div>
                <input @blur="blur(item)" v-if="item.isExit" type="text" v-model="item.name">
                <span v-else @dblclick="item.isExit = true">{{item.name}}</span> 
                <span>{{item.createTime}}</span>
            </div>
            <span @click="del(item.id)" v-show="active === i">删除</span>
        </li>
    </ul>
</template>

<script>
import { useStore } from 'vuex'
import { computed, ref } from 'vue'
export default {
    name: 'books',
    setup() {
        let store = useStore()
        let active = ref(null)
        let list = computed(() => store.state.data)
        // console.log(list);
        return {
            list: list,
            cur: computed(() => store.state.cur),
            active,
            del: (id) => store.commit('del', id),
            blur: (item) => {
                item.isExit = false
                // console.log(list);
                store.commit('changeData', list.value)
            }
        }
    }
}
</script>
<style lang="scss" scoped>
    .active {
        background-color: blue;
        color: #fff;
    }
    ul {
        padding: 0;
        margin: 0;
        list-style: none;
    }
    li {
        line-height: 40px;
        padding: 0 10px;
        display: flex;
        width: 100%;
        justify-content: space-between;
        span {
            cursor: pointer;
        }
    }
</style>